package Week5;

import java.util.*;

public class Day30 {
}

//牛客:爱吃素
class Main13 {
    public static boolean isPrim(long x){
        if(x < 2) return false;
        for(int i = 2; i <= Math.sqrt(x); i++){
            if(x % i == 0){
                return false;
            }
        }
        return true;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        while(n-- != 0){
            long a = in.nextLong() , b = in.nextLong();
            //当两个数a,b相乘后得到的结果一定不为素数.因为此时的值一定可以被a或b整除
            //但当a和b有一个数为为1时，同时另一个数为素数那么此时a*b的值才为素数
            if((b == 1 && isPrim(a)) || (a == 1 && isPrim(b))){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

//牛客:AB33 相差不超过k的最多数
class Main14 {
    //排序+滑动窗口
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt() , k = in.nextInt();
        int[] arr = new  int[n];
        for(int i = 0; i < n; i++){
            arr[i] = in.nextInt();
        }

        Arrays.sort(arr);
        int left = 0 , right = 0 , ret = 0;
        while(right < n){
            while(arr[right] - arr[left] > k){
                left++;
            }
            ret = Math.max(ret , right - left + 1);
            right++;
        }
        System.out.println(ret);
    }
}


//牛客:DP19 最长公共子序列(一)
class Main15 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt() , m = in.nextInt();
        char[] s1  = in.next().toCharArray();
        char[] s2  = in.next().toCharArray();

        //创建一个dp表。表示字符串s1中[0, i] 区间与字符串s2中[0, j]区间内所有的子序列中，最长公共子序列的长度是多少
        int[][] dp = new int[n + 1][m + 1];
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= m; j++){
                //如果字符相等
                if(s1[i - 1] == s2[j - 1]){
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                }else{
                    dp[i][j] = Math.max(dp[i - 1][j] , dp[i][j - 1]);
                }
            }
        }
        System.out.println(dp[n][m]);
    }
}